package com.libgdxbar.pvzlikegame.screens;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;

public abstract class GameScreenAdapter implements GameScreen {
	private final Vector2 viewCenter = new Vector2();
	protected ScreenManager screenManager;
	protected boolean initialized = false;
	protected boolean visible = true;
	private Viewport viewport;

	public GameScreenAdapter() {
	}

	public GameScreenAdapter(ScreenManager screenManager) {
		this.screenManager = screenManager;
	}
	//public abstract void gameRender(float delta);

	protected abstract void initViewport();

	public abstract void create();

	@Override
	public void initialize() {
		if (initialized) return;
		initViewport();
		create();
		initialized = true;
	}

	@Override
	public boolean isInitialized() {
		return initialized;
	}

	public ScreenManager getScreenManager() {
		return screenManager;
	}

	public void setScreenManager(ScreenManager screenManager) {
		this.screenManager = screenManager;
	}

	public void setViewport(float worldWidth, float worldHeight) {
		this.viewport = new FitViewport(worldWidth, worldHeight);
	}

	public Viewport getViewport() {
		return viewport;
	}

	public Vector2 getViewCenter() {
		viewCenter.set(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2);
		return viewCenter;
	}

	@Override
	public void show() {
		visible = true;
	}

	@Override
	public void render(float delta) {
		if (!visible) return;
		//gameRender(delta);
	}

	@Override
	public void resize(int width, int height) {
		if (viewport != null)
			viewport.update(width, height, true);
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	@Override
	public void hide() {
		visible = false;
	}

	@Override
	public void dispose() {
	}

}
